<#import "/spring.ftl" as s/>
<@override name="project">
         ${project.name}
</@override>
<@override name="main">
<ol class="wizard-nav">
    <li class="done"><a href="#"><span class="badge">1</span><small>发布信息</small></a></li>
    <li class="active"><a href="#"><span class="badge">2</span><small>触发构建</small></a></li>
    <li><a href="#"><span class="badge badge-info">3</span><small>缺陷报告</small></a></li>
    <li><a href="#"><span class="badge badge-warning">4</span><small>开发范围&特性描述</small></a></li>
    <li><a href="#" data-disabled><span class="badge badge-important">5</span><small>邮件通知&确认发布</small></a></li>
</ol><br/><br/><br/>
<fieldset >
    <legend>XXX</legend>
    <div id="step2_form_">
        <form id="step2_form" action="<@s.url '/project/milestone/wizard/wizard_form/'/>${milestone.id}" method="post">
            <table art="form" autoLabel="true"  rightAlign="true" columns="1,9" colon="true">
                <tr>
                    <td></td>
                    <td>
                        <input type="hidden" id="_page" name="_page" value="1">
                        <input type="text" id="buildResult" name="buildResult"  value="${milestoneReport.buildResult}">
                    </td>
                </tr>

                <tr>
                    <td>
                        <label art="label" for="projectName">项目名称</label>
                    </td>
                    <td>
                        <input type="text"art="textbox" id="projectName" name="projectName" readonly="true" value="${project.name}">
                    </td>
                </tr>

                <tr>
                    <td>
                        <label art="label" for="buildNote">构建号</label>
                    </td>
                    <td>
                        <input type="text" art="textbox" id="buildNote" name="buildNote" readonly="true" value="${milestoneReport.buildNote}"/>
                    </td>
                </tr>

                <#if milestoneReport.buildResult==true>
                    <tr>  <td></td>  <td> <div  style="background-color:#FFFFEC" align="left"><label style="color: red;">构建完成</label></div></td>
                    </tr>
                <#else>
                    <tr>
                        <td></td>
                        <td>
                            <div id="process" style="background-color:#FFFFEC" align="left">
                                <table border="0" width="80%" cellspacing="0" cellpadding="4" style="border-collapse: collapse"  height="20">
                                    <tr>
                                            <td>构建中...</td>
                                    </tr>
                                    <tr align="left">
                                        <td style="font-size:12px;">
                                            <div>
                                                <marquee style="border:1px solid #000000" direction="right" width="100%" scrollamount="20" scrolldelay="10" bgcolor="#ECF2FF">
                                                    <table cellspacing="1" cellpadding="0">
                                                        <tr height=10>
                                                            <td bgcolor=#3399FF width=10></td>
                                                            <td></td>
                                                            <td bgcolor=#3399FF width=10></td>
                                                            <td></td>
                                                            <td bgcolor=#3399FF width=10></td>
                                                            <td></td>
                                                            <td bgcolor=#3399FF width=10></td>
                                                            <td></td>
                                                        </tr>
                                                    </table>
                                                </marquee>
                                            </div>
                                        <#--<div id="result" style="display: none;"></div>-->
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </#if>


                <tr>
                    <td>
                    </td>
                    <td>
                        <textarea id="showContent" name="showContent"  art="textbox"   width=1000  height="200px" style="resize: none"readonly="true" ></textarea>
                    </td>
                </tr>

                <tr>
                    <td>
                    </td>
                    <td>
                        <button type="submit" value="previous" name="_target0"> <span><span>上一步</span></span></button>
                        <button type="submit" id="btn_next" value="next" name="_target2" disabled="disabled"> <span><span>下一步</span></span></button>
                        <button type="submit" name="_cancel" value="_cancel"><span><span>取消</span></span></button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</fieldset>
</@override>
<@override name="scripts">
<script type='text/javascript' src="<@s.url '/dwr/engine.js'/>"></script>
<script type='text/javascript' src="<@s.url '/dwr/util.js'/>"></script>
<script type="text/javascript" src="<@s.url '/dwr/interface/logReadDwr.js'/>"></script>
<script type="text/javascript" src="<@s.url '/dwr/interface/readlog.js'/>"></script>
<script type="text/javascript">
    var js_param = {
        get_build_result_url  : '<@s.url '/project/milestone/wizard/get_build_result'/>' ,
        do_build_url  : '<@s.url '/project/milestone/wizard/do_build'/>' ,
        get_build_status_url  : '<@s.url '/project/milestone/wizard/get_build_status'/>'
    }
    var milestoneId=${milestone.id};
    var tempResult;
    var releaseVersion=${milestoneReport.version};
    var log_name ='${project.code}'+"-"+milestoneId+"_build";
    var result =  $('#buildResult').attr('value');
//    var progressInterval = 500; // 定时器检查时间间隔
//    var progressTimer;   //定时器



    $(document).ready(function () {
           if(result) {
              $('#btn_next').removeAttr('disabled');
          }else{
               //（可能正在进行）     正在执行就不构建


               //否则  执行以下构建
               //异步执行构建
               //同时开启dwr引擎从后台push message到前台
               dwr.engine.setActiveReverseAjax(true);
               //开启某个日志文件读功能，加锁，防止写入
               readlog.setMilestoneId(milestoneId);
               readlog.toggle(log_name);

               var param ={"milestoneId":milestoneId,"releaseVersion":releaseVersion};
               cdms.common.ajax_post(js_param.do_build_url,param,function (data) {
                   check(data);
               });



               //没有构建成功的标记时。一进来就要进行一次检查 ，看是否需要部署构建（可能正在进行）

               //构建

               //并时刻检查构建情况
//               build_timer();
               }
    });

//      function build_timer(){
//          progressTimer = setInterval('check()',progressInterval);
//      }

      function check(data){
         if(data==""){
         	  $('#process').html("<label style='color: red;'>构建失败，请重新构建</label>");
         	  $('#buildResult').attr('value',false);
//         	  clean_out_timer();
         	  readlog.stop(log_name);
         }else{
            $('#process').html("<label style='color: red;'>构建完成</label>");
            $('#buildResult').attr('value',true);
//         	clean_out_timer();
         	readlog.stop(log_name);
       	    $('#btn_next').removeAttr('disabled');
         }
      }
//
    //    function clean_out_timer(){
    //        clearTimeout(progressTimer);
    //    }

    //反向Ajax回调函数
    function showContent(data) {
        $('#showContent').append(data+'\r\n')
    }
</script>
</@override>
<@extends name="/common/projectlayout1.1.ftl" current="milestone" title='${title}' code='${project.code}'></@extends>